import {Injectable} from '@angular/core';
import {HttpClient, HttpHeaders} from '@angular/common/http';

@Injectable({
  providedIn: 'root'
})
export class RentClassManageService {

  serviceUrls = {
    queryRentPlaneListUrl: '/goodsTypeRent/', // 租机分类列表
    saveRentPlaneListUrl: '/goodsTypeRent/save', // 租机分类列表 - 新增
    updateRentPlaneListUrl: '/goodsTypeRent/update', // 租机分类列表 - 编辑
    deleteRentPlaneUrl: '/goodsTypeRent/delete', // 租机分类 - 删除
    queryRentGoodsListUrl: '/goodsRent/typeFindList', // 查询租机商品列表
    updateRelationRentGoodsUrl: '/goodsRent/updateTypes', // 租机批量修改关联商品(关联 | 移除)
  };

  constructor(
    public httpClient: HttpClient
  ) {}

  // 查询租机分类列表
  getRentPlaneList(params: any) {
    return this.httpClient.get(this.serviceUrls.queryRentPlaneListUrl, {params}).toPromise();
  }

  /**
   * 新增 | 编辑
   * @param params 
   * @returns 
   */
  editClassItemData(params: any, type: number = 0) {
    let url = type === 0 ? this.serviceUrls.saveRentPlaneListUrl : this.serviceUrls.updateRentPlaneListUrl;
    return this.httpClient.post(url, params).toPromise();
  }

  /**
   * 删除
   * @param params 
   * @returns 
   */
  deteleClassData(params: any) {
    return this.httpClient.post(this.serviceUrls.deleteRentPlaneUrl, params).toPromise();
  }

  /**
   * 获取上级分类list
   * @param type 1；一级 2：二级
   * @returns 
   */
  getSuperiorClassList(type: any) {
    let params = {
      level: type
    }
    return this.httpClient.get(`${this.serviceUrls.queryRentPlaneListUrl}get`, {params}).toPromise();
  }

  // 获取租机商品列表
  getRentGoodsListData(params: any) {
    return this.httpClient.post(this.serviceUrls.queryRentGoodsListUrl, params).toPromise();
  }

  // 租机批量修改关联商品
  updateRentRelationGoods(params: any) {
    return this.httpClient.post(this.serviceUrls.updateRelationRentGoodsUrl, params).toPromise();
  }
}
